/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

/**
 *
 * @author Green
 */
public class ImageUtility {

    private static ImageUtility instance = null;
    public static ImageUtility getInstance() {
        if(instance == null)
            instance = new ImageUtility();
        return instance;
    }

    public static BufferedImage loadImageFromResource(String path) {
        ImageIcon imgi = new ImageIcon(new ImageUtility().getClass().getResource(path));
        BufferedImage b = new BufferedImage(imgi.getIconWidth(), imgi.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics g = b.getGraphics();
        g.drawImage(imgi.getImage(), imgi.getIconWidth(), imgi.getIconHeight(), null);

        return b;
    }

    public static BufferedImage loadImageFromResource_(String path) {
        URL url = ImageUtility.getInstance().getClass().getResource(path);
        BufferedImage img = null;
        try {
            img = ImageIO.read(url);
        } catch (IOException ex) {
            Logger.getLogger(ImageUtility.class.getName()).log(Level.SEVERE, null, ex);
        }

        return img;
    }
    
}
